package org.openclinic.repository;

import java.util.List;

import org.openclinic.domain.Attendant;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public interface AttendantRepository extends JpaRepository<Attendant, Long> {

	@Query
	Attendant findByCpfAndPassword(String cpf, String password);
	
	@Query("FROM Attendant WHERE bond = 2 ORDER BY name")
	List<Attendant> findAllAttendants();
	
	@Modifying
	@Transactional(propagation = Propagation.REQUIRED)
	@Query("UPDATE Attendant SET password = ?1 WHERE password = ?2 AND user_id = ?3")
	int updatePassword(String newPassword, String currentPassword, long userId);
}
